Skip to content

Conversation

@javier-godoy
Copy link
Member

@javier-godoy javier-godoy commented Nov 13, 2025

Add a helper for executeJs.then(SerializableConsumer,...) (the original method receives a SerializableConsumer<JsonNode> in Vaadin 25, and a SerializableConsumer<JsonValue> in earlier versions).

Summary by CodeRabbit

  • New Features
    • Added new API for asynchronous JavaScript execution with support for handling successful results and error callbacks.

@javier-godoy javier-godoy marked this pull request as ready for review November 13, 2025 19:20
@paodb
Copy link
Member

paodb commented Nov 13, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Nov 13, 2025

Walkthrough

This PR introduces a new public API for asynchronous JavaScript execution with JSON compatibility across Vaadin versions. A new ElementalPendingJavaScriptResult interface and corresponding executeJs method in JsonMigration are added to wrap browser-side execution results through version-specific converter implementations.

Changes

Cohort / File(s) Summary
New Interface Definition
src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalPendingJavaScriptResult.java
Introduces public interface extending Serializable with two overloads of then() method: one accepting both result and error handlers, and one accepting only a result handler. Enables asynchronous handling of JavaScript execution results as JsonValue.
Public API Method
src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigration.java
Adds public static executeJs(Element, String, Serializable...) method that delegates to element's native execution and converts the result via helper's conversion method, providing a wrapped ElementalPendingJavaScriptResult return type.
Interface Contract
src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper.java
Extends interface with new convertPendingJavaScriptResult() method that converts Vaadin's PendingJavaScriptResult to ElementalPendingJavaScriptResult.
Version-Specific Implementations
src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper25.java, src/main/java/com/flowingcode/vaadin/jsonmigration/LegacyJsonMigrationHelper.java
Both implement the converter method with private inner wrapper classes: JsonMigrationHelper25 uses explicit JsonNode-to-JsonValue adaptation in a PendingJavaScriptResultImpl inner class; LegacyJsonMigrationHelper uses Lombok's @Delegate to forward all behavior to the wrapped result.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify the JsonNode-to-JsonValue conversion logic in JsonMigrationHelper25's inner class correctly adapts the callback handlers
  • Ensure the @Delegate pattern in LegacyJsonMigrationHelper properly implements the ElementalPendingJavaScriptResult interface contract
  • Confirm that the executeJs method's varargs parameter handling (Serializable...) aligns with the element API expectations
  • Check serialization compatibility and @SuppressWarnings annotations across wrapper implementations

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a helper for executeJs with proper handling of SerializableConsumer for asynchronous JavaScript execution across Vaadin versions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch executejs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper25.java (1)

154-164: Consider improving type safety in the wrap method.

The current implementation uses a raw SerializableConsumer return type and requires @SuppressWarnings annotations. This can be refactored for better type safety:

Apply this diff to eliminate raw types:

-    @SuppressWarnings("rawtypes")
-    private static SerializableConsumer wrap(SerializableConsumer<JsonValue> resultHandler) {
-      return (SerializableConsumer<JsonNode>) node -> resultHandler.accept(convertToJsonValue(node));
+    private static SerializableConsumer<JsonNode> wrap(SerializableConsumer<JsonValue> resultHandler) {
+      return node -> resultHandler.accept(convertToJsonValue(node));
     };
 
     @Override
-    @SuppressWarnings("unchecked")
     public void then(SerializableConsumer<JsonValue> resultHandler,
         SerializableConsumer<String> errorHandler) {
       delegate.then(wrap(resultHandler), errorHandler);

This makes the type conversion explicit and eliminates the need for suppression annotations.

src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper.java (1)

34-34: Add JavaDoc documentation for this public API method.

This interface method lacks documentation for users to understand its purpose, parameters, return value, and behavior. Public API methods should include clear JavaDoc explaining the conversion and any null-handling behavior.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a14325 and 5a168a6.

📒 Files selected for processing (5)
  • src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalPendingJavaScriptResult.java (1 hunks)
  • src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigration.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper25.java (2 hunks)
  • src/main/java/com/flowingcode/vaadin/jsonmigration/LegacyJsonMigrationHelper.java (2 hunks)
🔇 Additional comments (6)
src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigration.java (1)

119-133: LGTM! Well-documented public API addition.

The executeJs method properly delegates to Vaadin's native API and applies version-specific conversion through the helper. The javadoc clearly explains the purpose and references the underlying Vaadin API.

src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper25.java (1)

142-146: LGTM! Proper wrapper instantiation for Vaadin 25+.

The conversion method correctly instantiates the version-specific wrapper that handles JsonNode↔JsonValue conversion.

src/main/java/com/flowingcode/vaadin/jsonmigration/ElementalPendingJavaScriptResult.java (2)

1-35: Proper attribution with dual copyright headers.

The dual copyright (Flowing Code + Vaadin Ltd) is appropriate since this interface is derived from Vaadin's PendingJavaScriptResult API. Both use Apache 2.0 licensing, ensuring compatibility.


42-89: LGTM! Well-designed compatibility interface.

The interface provides a clean abstraction over PendingJavaScriptResult using elemental.json.JsonValue to maintain compatibility across Vaadin versions. The documentation is comprehensive, explaining async behavior and session locking constraints. The default convenience method properly delegates to the main method.

src/main/java/com/flowingcode/vaadin/jsonmigration/LegacyJsonMigrationHelper.java (1)

49-61: Elegant delegation pattern for legacy Vaadin versions.

The implementation correctly wraps PendingJavaScriptResult using Lombok's @Delegate annotation. In Vaadin 24 and earlier, PendingJavaScriptResult.then() uses SerializableConsumer<JsonValue>, making this delegation approach work cleanly for pre-Vaadin 25 compatibility.

src/main/java/com/flowingcode/vaadin/jsonmigration/JsonMigrationHelper.java (1)

22-22: LGTM!

The import is necessary for the new method and correctly placed.

@paodb paodb merged commit eb84a1e into master Nov 14, 2025
2 checks passed
@paodb paodb deleted the executejs branch November 14, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants